package com.javaGame.role.enemy;

import com.javaGame.frame.MainFrame;
import com.javaGame.role.BaseRole;
import com.javaGame.role.Bomb;

/**
 * 所有怪物父类
 */
public abstract class EnemyRole extends BaseRole {
    /**生命*/
    protected int hp;
    /**经验*/
    protected int exp;

    public EnemyRole(int x, int y, int width, int height,int hp,int exp) {
        super(x, y, width, height);
        this.hp = hp;
        this.exp = exp;
    }

    /**
     * 怪物被击中
     * @param delHp 减少生命
     */
    public void byHit(int delHp){
        //生命减少
        this.hp -= delHp;
        //当生命减少为0时，怪物死亡
        if(this.hp <= 0 ){
            //增加得分
            MainFrame.pointer += this.exp;
            //从角色集合中移除怪物
            MainFrame.roleList.remove(this);
            //产生爆炸
            this.addBomb();
        }
    }

    public int getHp() {
        return hp;
    }

    /**
     * 产生爆炸
     */
    public void addBomb(){
        MainFrame.roleList.add(new Bomb(this.x,this.y));
    }
}
